if(!$args[0]) { Write-Output "Year - NULL in argument" exit 1 } $year = $args[0] if($args[0] -ne "1" -and $args[0] -ne "2" -and $args[0] -ne "3") { Write-Output "Invalid Year : $year" exit 1 } if(!$args[1]) { Write-Output "ESU Key - NULL in argument" exit 1 } $esukey = $args[1] $osname = (Get-WmiObject Win32_OperatingSystem).Caption Write-Output "OSName : $osname" $activationid = "" if($osname -ilike "*Server 2008*") { Write-Output "Server OS" if($year -eq "1") { Write-Output "Checking for Year 1" $activationid = "553673ed-6ddf-419c-a153-b760283472fd" } elseif($year -eq "2") { Write-Output "Checking for Year 2" $activationid = "04fa0286-fa74-401e-bbe9-fbfbb158010d" } elseif($year -eq "3") { Write-Output "Checking for Year 3" $activationid = "16c08c85-0c8b-4009-9b2b-f1f7319e45f9" } else { Write-Output "Invalid Year $year" } } elseif($osname -like "*Windows 7*") { Write-Output "Workstation OS" if($year -eq "1") { Write-Output "Checking for Year 1" $activationid = "77db037b-95c3-48d7-a3ab-a9c6d41093e0" } elseif($year -eq "2") { Write-Output "Checking for Year 2" $activationid = "0e00c25d-8795-4fb7-9572-3803d91b6880" } elseif($year -eq "3") { Write-Output "Checking for Year 3" $activationid = "4220f546-f522-46df-8202-4d07afd26454" } else { Write-Output "Invalid Year $year" exit 1 } } else { Write-Output "Not applicable for OS : $osname" exit 1 } $LicenseStatus = (Get-WmiObject -query "SELECT * FROM SoftwareLicensingProduct WHERE ID like '$activationid'").LicenseStatus if($LicenseStatus -eq "1") { Write-Output "ESU Installed and Licensed" exit 0 } elseif($LicenseStatus -eq "0") { Write-Output "ESU Installed but Unlicensed, will help you to activate ESU key" cscript.exe C:\windows\system32\slmgr.vbs /ato $activationid } else { Write-Output "Can’t find this ESU key, will help you to add and activate ESU key" cscript.exe C:\windows\system32\slmgr.vbs /ipk $esukey cscript.exe C:\windows\system32\slmgr.vbs /ato $activationid } $LicenseStatus = (Get-WmiObject -query "SELECT * FROM SoftwareLicensingProduct WHERE ID like '$activationid'").LicenseStatus if($LicenseStatus -eq "1") { Write-Output "ESU Installed and Licensed" exit 0 } elseif($LicenseStatus -eq "0") { Write-Output "Failed to activate ESU license." exit 1 } else { Write-Output "Failed to install ESU license." exit 1 }